package cn.tedu.bece.front.service.impl;

import cn.tedu.bece.front.common.exception.ServiceException;
import cn.tedu.bece.front.mapper.DiaryMapper;
import cn.tedu.bece.front.pojo.dto.DiaryQuery;
import cn.tedu.bece.front.pojo.dto.DiarySaveParam;
import cn.tedu.bece.front.pojo.entity.Diary;
import cn.tedu.bece.front.pojo.vo.DiaryVO;
import cn.tedu.bece.front.service.DiaryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Slf4j
@Service
public class DiaryServiceImpl implements DiaryService {
    @Autowired
    DiaryMapper diaryMapper;

    @Override
    public void saveDiary(DiarySaveParam diarySaveParam) {
        log.debug("保存日记业务，参数：{}",diarySaveParam);
        Diary diary = new Diary();
        BeanUtils.copyProperties(diarySaveParam,diary);
        diary.setWriteTime(new Date());

        diaryMapper.saveDiary(diary);
    }

    @Override
    public List<DiaryVO> selectDiary(DiaryQuery diaryQuery) {
        log.debug("查询日记业务：参数：{}",diaryQuery);
        List<DiaryVO> list = diaryMapper.selectDiary(diaryQuery);
        return list;
    }
}
